#include <iostream>
#include <unistd.h>
#include "Comm.hpp"
int main()
{
    char buffer[1024];
    setNoneBlock(0);
    while (true)
    {
        int n = read(0, buffer, sizeof(buffer) - 1);

        if (n > 0)
        {
            buffer[n] = 0;
            std::cout << "Ehco# " << buffer << std::endl;
        }
        else if (n == 0)
        {
            std::cout << "read done" << std::endl;
            break;
        }
        else 
        {
            if (errno == EINTR)
            {
                std::cout << "信号被中断，重新进行读取"<<std::endl;
                continue;
            }
            else if (errno == EWOULDBLOCK)
            {
                sleep(1);
                std::cout << "底层数据没有就绪，开始轮询检测"<<std::endl;
                std::cout << "dootherthing"<<std::endl;
                continue;
            }
            else 
            {
                perror("read");
                break;
            }
        }
    }

    return 0;
}